// ////////////////////////////////////////////////////////////////////////////////////////
// NAME: WhiteList.java 
// AUTHOR: CDT Peter Lofreddo 
// LAST MODIFIED: 28 March 2012 
// DESCRIPTION: Contains information for Reading a file as clickable listview
// LIMITATIONS: 
// CITATIONS: In code
// 
// ////////////////////////////////////////////////////////////////////////////////////////
package prototype.revision;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import android.os.Environment;
import android.util.Log;

public class WhiteList extends GenericActivity {
	String[] whitey = null;
	private String name;

	public WhiteList(String fileName) {
		name = fileName;
	}

	public String[] ReadFileAsList() {
		// ////////////////////////////////////////////////////////////////////////////////////////
		// NAME: ReadFileAsList(String fileName)
		// AUTHOR: CDT Peter Lofreddo
		// LAST MODIFIED: 12 February 2012
		// DESCRIPTION: Views file as a clickable ListView
		// LIMITATIONS: Search Queries cast to lowercase for ease of use.
		// CITATIONS: Adapted from http://stackoverflow.com/questions/8526831/
		// how-to-display-data-from-a-text-file-in-a-listview
		//
		// ////////////////////////////////////////////////////////////////////////////////////////

		try {
			// Creates a new object
			File f = new File(Environment.getExternalStorageDirectory()
					+ "/Nullwall/" + name);
			FileInputStream fileIS = new FileInputStream(f);
			BufferedReader buf = new BufferedReader(new InputStreamReader(
					fileIS));
			StringBuilder DbLines = new StringBuilder();
			String line = buf.readLine();
			// iterates through file
			while (buf.readLine() != null) {
				DbLines.append(line);
				DbLines.append("\r\n");
			}
			// Splits the string on a new line to put into each listview
			String[] ListItems = DbLines.toString().split("\r\n");
			// returns the list
			return ListItems;
		}

		catch (FileNotFoundException e) {

			e.printStackTrace();
			Log.e("FileOp_ReadFileAsList", "File Not Found in ReadFileAsList()");

		} catch (IOException e) {
			e.printStackTrace();
			Log.e("FileOp_ReadFileAsList", "IOException in ReadFileAsList()");
		}
		Log.e("FileOp_ReadFileAsList", "Probably an Error in ReadFileAsList()");
		return null;

	}
}
